<template>
  <div class="flex p_0_20">
    <el-tooltip content="刷新" placement="bottom">
      <svgBtn
        class="table_header"
        :style="{
          backgroundColor: svg_color_list[0] == '#3580eb' ? '#ECF4FF' : '',
        }"
        :color="svg_color_list[0]"
        @mouseenter="svg_color_list[0] = '#3580eb'"
        @mouseleave="svg_color_list[0] = '#45474A'"
        icon="table_refresh"
        @click="EventBus.emit('refresh')"
      ></svgBtn
    ></el-tooltip>
    <el-dropdown :hide-on-click="false">
      <svgBtn
        class="table_header"
        :style="{
          backgroundColor: svg_color_list[1] == '#3580eb' ? '#ECF4FF' : '',
        }"
        :color="svg_color_list[1]"
        @mouseenter="svg_color_list[1] = '#3580eb'"
        @mouseleave="svg_color_list[1] = '#45474A'"
        icon="table_height"
      ></svgBtn>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item
            :style="{ color: height_size == 1 ? '#3580EB' : '' }"
            @click="$emit('changeHeightSize', 1)"
            >默认
            <svgBtn
              icon="xuanzhong"
              style="font-size: 12px"
              v-if="height_size == 1"
              class="m_left10"
            ></svgBtn
          ></el-dropdown-item>
          <el-dropdown-item
            :style="{ color: height_size == 2 ? '#3580EB' : '' }"
            @click="$emit('changeHeightSize', 2)"
            >中等
            <svgBtn
              icon="xuanzhong"
              style="font-size: 12px"
              v-if="height_size == 2"
              class="m_left10"
            ></svgBtn
          ></el-dropdown-item>
          <el-dropdown-item
            :style="{ color: height_size == 3 ? '#3580EB' : '' }"
            @click="$emit('changeHeightSize', 3)"
            >紧凑
            <svgBtn
              icon="xuanzhong"
              style="font-size: 12px"
              v-if="height_size == 3"
              class="m_left10"
            ></svgBtn
          ></el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
    <el-dropdown :hide-on-click="false" placement="top">
      <svgBtn
        class="table_header"
        :style="{
          backgroundColor: svg_color_list[2] == '#3580eb' ? '#ECF4FF' : '',
        }"
        :color="svg_color_list[2]"
        @mouseenter="svg_color_list[2] = '#3580eb'"
        @mouseleave="svg_color_list[2] = '#45474A'"
        icon="table_header"
      ></svgBtn>
      <template #dropdown>
        <el-dropdown-menu>
          <div class="m_0_10 border_bottom p_10">
            <div class="flex_js">
              <span class="fw fs_14">列展示</span>
              <el-button @click="$emit('resetTableSet')">重置</el-button>
            </div>
          </div>
          <div
            :style="{ maxHeight: max_height ? max_height : '' }"
            style="overflow-y: auto"
          >
            <el-dropdown-item
              v-for="(item, index) in data"
              :key="index"
              @click="$emit('changeShowTable', index)"
            >
              <div class="flex">
                <svgBtn
                  icon="xuanzhong_1"
                  style="font-size: 14px"
                  v-if="item.showTable"
                  class="m_right10"
                ></svgBtn>
                <span v-else class="checkbox_empty"></span>
                <span class="m_left10">{{ item.label }}</span>
              </div>
            </el-dropdown-item>
          </div>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts" setup>
import svgBtn from '@/components/svg_button.vue'
import { ref } from 'vue'
import EventBus from '@/utils/EventBus'
const svg_color_list = ref(['#45474A', '#45474A', '#45474A'])
const props = defineProps({
  data: {
    type: Object,
    default: {},
  },
  height_size: {
    type: Number,
    default: 1,
  },
  max_height: {
    type: String,
  },
})
</script>

<style lang="scss" scoped>
.table_header {
  font-size: 20px !important;
  padding: 5px;
  margin: 0 10px;
  border-radius: 3px;
  height: 20px;
  line-height: 20px;
}
.checkbox_empty {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1px solid #68686a;
  border-radius: 2px;
  margin-right: 10px;
}
.checkbox_empty:hover {
  border-color: #3580eb;
}
</style>
